package com.greedy.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @Author: Yanxy
 * @Date: Created in:2022-12-24
 * Description: 统一结果返回
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result {

    /**
     * 成功/失败
     */
    private Boolean success;
    /**
     * 失败原因
     */
    private String errorMsg;
    /**
     * 响应数据
     */
    private Object data;
    private Long total;

    public static Result ok(){
        return new Result(true, null, null, null);
    }
    public static Result ok(Object data){
        return new Result(true, null, data, null);
    }
    public static Result ok(List<?> data, Long total){
        return new Result(true, null, data, total);
    }
    public static Result fail(String errorMsg){
        return new Result(false, errorMsg, null, null);
    }

}
